<?php

/**
 * Created by PhpStorm.
 * User: GadflyBSD
 * Date: 16/3/12
 * Time: 11:36
 */
class ManageAction extends CommonAction{
	public function _initialize(){
		parent::_initialize();
		$this->assign('title', '汪卡商户订单系统');
	}

	public function index(){
		$this->display();
	}

	public function angularAjax($post){
		switch($post['op']){
			case 'getShopInfo':
				return D('Business')->getShopInfo($post['sid'], 'sid');
			case 'setVipLimit':
				return D('Manage')->setVipLimit($post);
			case 'getShopList':
				return D('Business')->getShopList();
			case 'getSurveyList':
				return D('Customer')->getSurveyList();
			case 'sendSms':
				Vendor('ChinaPnr');
				$pnr = new ChinaPnr('finance');
				$result = $pnr->securityCode(array('user_mobile' => $post['mobile']), '101');
				return $result['data']['resp_desc'];
			case 'settleOrder':
				return D('Manage')->sttleOrder();
			case 'getSettleList':
				return D('Manage')->getSettleList($post['start'], $post['end']);
			case 'removeSurveyBind':
				return D('Manage')->removeSurveyBind($post['bid']);
		}
	}

	/**
	 * 汇付天下接口企业开户
	 */
	public function openBusinessAccount(){
		Vendor('ChinaPnr');
		$pnr = new ChinaPnr('finance');
		$data = array(
			'apply_id'              => 'zdbusiness',
			'operate'               => 'add',
			'corp_type'             => 'c2',
			'corp_name'             => '昆明市经开区中道小额贷款股份有限公司',
			'social_credit_code'    => '9153010057980893X4',             // 企业的统一社会信用代码
			'license_start_date'    => '20110722',             // 企业的营业证照起始日期,精确到年月日
			'license_end_date'      => '99991231',               // 企业的营业证照结束日期,精确到年月日,99991231 表示永久
			'corp_business_address' => '昆明经开区出口加工区电子及信息产业物流功能区工业三区浦发路中道集团大厦',          // 企业的经营地址,中文应使用UTF-8 字符集 URLEncode 编码后传入
			'corp_reg_address'      => '昆明经开区出口加工区电子及信息产业物流功能区工业三区浦发路中道集团大厦',               // 企业的注册地址,中文应使用UTF-8 字符集 URLEncode 编码后传入
			'corp_fixed_telephone'  => '0871-63662858',           // 企业的固定电话
			'business_scope'        => '办理经开区域内各项小额贷款；为经开区域内小企业发展、管理、财务等提供咨询服务；其他经审查的业务（依法须经批准的项目，经相关部门批准后方可开展经营活动）',  // 企业的经营范围,中文应使用UTF-8 字符集 URLEncode 编码后传入
			'controlling_shareholder' => '马武 金琳雁 朱建华 王硕 杨庆玲 杨家雄 陈花兰 黄蕊',      // 企业的控股股东,中文应使用必须UTF-8 字符集 URLEncode 编码后传入
			'legal_name'            => '马武',                     // 企业的法人姓名,中文应使用必须UTF-8 字符集 URLEncode 编码后传入
			'legal_cert_type'       => 'l1',        // 法人证件类型 l1:身份证 l2:护照 l3:军官证 l4:士兵证 l5:回乡证 l6:警官证 l7:台胞证 l8:其他
			'legal_cert_id'         => '530111196912280857',                  // 法人的证件号码,与证件类型对应
			'legal_mobile'          => '13908719181',                   // 法定代表人的手机号码
			'legal_cert_start_date' => '20120413',          // 法定代表人的证件起始日期,精确到年月日
			'legal_cert_end_date'   => '20320413',            // 法定代表人的证件结束日期,精确到年月日,99991231 表示永久
			'contact_name'          => '戴卫国',                   // 企业联系人的姓名,中文应使用UTF-8 字符集 URLEncode 编码后传入
			'contact_mobile'        => '18687519319',                 // 联系人的手机号码
			'contact_email'         => '358757091@qq.com',                  // 联系人的邮箱地址
			'bank_acct_name'        => '昆明市经开区中道小额贷款股份有限公司',                 // 企业开户银行账户名,需与企业名称保持一致,中文应使用UTF-8 字符集 URLEncode 编码后传入
			'bank_id'               => '03020000',                        // 充值/取现支持银行列表及代号
			'bank_acct_no'          => '7303210181700000177',                   // 企业开户银行账号
			'bank_branch'           => '昆明经开区支行',                    // 企业开户银行的支行名称,中文应使用UTF-8 字符集 URLEncode 编码后传入
			'bank_prov'             => '0053',                      // 银行卡开户省份
			'bank_area'             => '5301',
		);
		print($pnr->openAccount($data, 'business'));
	}

	/**
	 * 企业用户充值
	 */
	public function recharge(){
		Vendor('ChinaPnr');
		$pnr = new ChinaPnr('finance');
		switch(I('post.user_cust_id')){
			case '6666000000031462':
				$post = array(
					'user_cust_id'  => I('post.user_cust_id'),
					'trans_amt'     => I('post.money').'.00',
				);
				print($pnr->recharge($post, '01050000', 'D', 'recharge', 'business'));
				break;
			case '6666000000030243':
				$post = array(
					'user_cust_id'  => I('post.user_cust_id'),
					'trans_amt'     => I('post.money').'.00',
				);
				print($pnr->recharge($post, '01050000', 'D', 'recharge', 'business'));
				break;
			case '32466-32467':
				$post = array(
					'out_cust_id'   => '6666000000030243',
					'out_acct_id'   => '32466',
					'in_cust_id'    => '6666000000030243',
					'in_acct_id'    => '32467',
					'transfer_amt'  => I('post.money').'.00',
				);
				$transfer = $pnr->transfer($post, 'BusinessSubAccount');
				dump($transfer);
				break;
			case '32466-33798':
				$post = array(
					'out_cust_id'   => '6666000000030243',
					'out_acct_id'   => '32466',
					'in_cust_id'    => '6666000000031462',
					'in_acct_id'    => '33798',
					'transfer_amt'  => I('post.money').'.00',
				);
				$transfer = $pnr->transfer($post);
				dump($transfer);
				break;
		}
	}

	public function pass(){
		echo md5(md5(I('get.p')).'e3e15e');
	}

	public function balance(){
		Vendor('ChinaPnr');
		$pnr = new ChinaPnr('finance');
		dump($pnr->balance(array('user_cust_id' => '6666000000031462')));
		echo '<hr />';
		dump($pnr->balance(array('user_cust_id' => '6666000000030243')));
	}

	public function transfer(){
		Vendor('ChinaPnr');
		$pnr = new ChinaPnr('finance');
		$post = array(
			'out_cust_id'   => '6666000000030243',
			'out_acct_id'   => '32466',
			'in_cust_id'    => '6666000000031462',
			'in_acct_id'    => '33798',
			'transfer_amt'  => '327.13',
		);
		$transfer = $pnr->transfer($post);
		dump($transfer);
	}
	
	public function withdraw(){
		Vendor('ChinaPnr');
		$pnr = new ChinaPnr('finance');
		dump($pnr->withdraw(array(
			'user_cust_id'  => '6666000000031462',
			'trans_amt'     => '79922.81',
			'card_no'       => '7303210181700000177',
			), 't0'));
	}
}